package com.hmall.controller;

import com.hdmall.business.common.annotation.LoginRequired;
import com.hdmall.business.common.common.ServerResponse;
import com.hmall.vo.MallHotVo;
import com.hmall.service.ProductClassService;
import com.hmall.util.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author zhoutao
 */
@RestController
@RequestMapping("/product/")
@CrossOrigin(origins = "http://localhost:8088", maxAge = 3600)
@Api(value = "产品操作API", description = "产品页上推荐产品接口")
public class ProductController {

    private final ProductClassService iProductClassService;


    TokenUtil tokenUtil = new TokenUtil();

    @Autowired
    public ProductController(ProductClassService iProductClassService) {
        this.iProductClassService = iProductClassService;
    }

    @GetMapping("test")
    @ApiOperation(value = "test")
    public ServerResponse test(){
        return ServerResponse.createBySuccess("1111");
    }



    /**
     * @Date 2018/11/9 10:53
     * @Param [hotCount, shopId]
     * @return com.hmall.common.ServerResponse<java.util.List<com.hmall.vo.MallHotVo>>
     * @Description // 商家热推
     */
    @GetMapping("hotPush")
    @ApiOperation(value = "商家热推")
    public ServerResponse<List<MallHotVo>> hotPush(@RequestParam(value = "hotCount", defaultValue = "6") Integer hotCount, @RequestParam(value = "shopId", defaultValue = "1") Integer shopId) {

        return iProductClassService.listHotPush(hotCount, shopId);
    }


    /**
     * @Date 2018/11/9 10:54
     * @Param [similarCount, productId, shopId]
     * @return com.hmall.common.ServerResponse<java.util.List<com.hmall.vo.MallHotVo>>
     * @Description // 相似推荐
     */
    @PostMapping("similar")
    @ApiOperation(value = "相似推荐")
    public ServerResponse<List<MallHotVo>> similarPush(@RequestParam(value = "similarCount", defaultValue = "6") Integer similarCount,
                                                       Integer productId, @RequestParam(value = "shopId", defaultValue = "1") Integer shopId) {

        return iProductClassService.listSimilarPush(similarCount, productId, shopId);

    }
    @LoginRequired
    @GetMapping(value = "cancelOrder")
    @ApiOperation(value = "取消订单")
    public ServerResponse cancelOrder(String token, Long orderNo) {

        return iProductClassService.cancelOrder(orderNo);
    }


}
